package org.lease.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.lease.common.result.Result;
import org.lease.model.entity.LeaseTerm;
import org.lease.service.LeaseTermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "租期管理")
@RestController
@RequestMapping("/admin/term")
public class LeaseTermController {
    @Autowired
    private LeaseTermService leaseTermService;

    @Operation(summary = "查询所有租期")
    @GetMapping("/list")
    public Result<List<LeaseTerm>> findAll() {
        List<LeaseTerm> list = leaseTermService.list();

        log.info("查询所有租期，结果：{}", list);
        return Result.success(list);
    }

    @Operation(summary = "保存或更新租期信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        leaseTermService.saveOrUpdate(leaseTerm);
        return Result.success();
    }

    @Operation(summary = "根据 ID 删除租期信息")
    @DeleteMapping("/deleteById")
    public Result deleteById(Long id) {
        leaseTermService.removeById(id);
        return Result.success();
    }
}
